﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace luanvanFinal
{
    /// <summary>
    /// Interaction logic for wdInsertStageDetail.xaml
    /// </summary>
    public partial class wdInsertStageDetail : Window
    {
        int idStage;
        public wdInsertStageDetail()
        {
            InitializeComponent();
        }
        public int IdStage
        {
            get { return idStage; }
            set { idStage = value; }
        }
        public void insertStageDetail()
        {
            Boolean checkTitle = false;
            String SQL = "select title from stageDetail where idStage='"+idStage+"'";
            clsStageDetail check = new clsStageDetail();
            DataTable dt = check.getDataStageDetail(SQL);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (tbTitle.Text == dt.Rows[i][0].ToString())
                    checkTitle = true;
            }
            clsStageDetail stageDetail = new clsStageDetail();
            stageDetail.Title = tbTitle.Text;
            stageDetail.IdStage = idStage;
            stageDetail.Detail = new TextRange(detail.Document.ContentStart, detail.Document.ContentEnd).Text;
            stageDetail.WorkPercent = 0;
            if (checkTitle == false)
            {
                stageDetail.insertStageDetail();
                MessageBox.Show("You have inserted Stage Detail success !!!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("This Title had existed in this Stage", "Success", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            insertStageDetail();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        public void loadForm()
        {
            clsStage stage = new clsStage();
            String SQL="select idProject, title from stage where Id = '"+idStage+"'";
            DataTable dt = stage.getDataStage(SQL);
            clsProject project = new clsProject();
            tbProject.Text = project.getNameFromId(Convert.ToInt32(dt.Rows[0][0].ToString()));
            tbStage.Text = dt.Rows[0][1].ToString();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loadForm();
        }
    }
}
